package com.mjlf.shiro.login;

import com.mjlf.shiro.sha.HashService;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;

import java.util.Arrays;

/**
 * @ClassName ShiroCredentialsMatcher
 * @auther mjlf
 * @Date 2019/6/11 11:15
 * @Description TODO
 */
public class ShiroCredentialsMatcher implements CredentialsMatcher {

    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        UsernamePasswordToken passwordToken = (UsernamePasswordToken)token;

        System.out.println(passwordToken.getUsername());
        System.out.println(info.getPrincipals());
        if(passwordToken.getUsername().equals(info.getPrincipals().toString())){
            if(HashService.hash(String.copyValueOf(passwordToken.getPassword()), "123").equals(info.getCredentials())){
                return true;
            }
        }
        return false;
    }
}
